package com.zengqingfa.springboot.redis.rest;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zengqingfa.springboot.redis.entity.User;
import com.zengqingfa.springboot.redis.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Author: SLFX
 * @Date: 2022-07-27
 * @Description:
 **/
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;


    @GetMapping("/getById")
    public User getById(@RequestParam("id") Long id) {
        return userService.getById(id);
    }

    @GetMapping("/list")
    public List<User> list(User user) {
        return userService.listUser(user);
    }

    @GetMapping("/listByPage")
    public IPage<User> listUserByPage(Page<User> page, User user, HttpServletRequest request) {
        String currentUserId = request.getHeader("USER_ID");
        return userService.listUserByPage(page,user,currentUserId);
    }

    @PostMapping("/add")
    public Integer add(@RequestBody User user) {
        return userService.add(user);
    }

    @PostMapping("/updateById")
    public Boolean modifyById(@RequestBody User user) {
        return userService.modifyById(user);
    }

    @PostMapping("/batchUpdateByIds")
    public Boolean batchUpdateByIds(@RequestBody List<User> users) {
        return userService.batchUpdateByIds(users);
    }

    @DeleteMapping("/deleteById")
    public Boolean deleteById(@RequestParam("id") Integer id) {
        return userService.deleteById(id);
    }

    /**
     * 获取最近的搜索历史
     * @param request
     * @return
     */
    @GetMapping("/getSearchUserNameHistory")
    public List<String> getSearchUserNameHistory( HttpServletRequest request) {
        String currentUserId = request.getHeader("USER_ID");
        return userService.getSearchUserNameHistory(currentUserId);
    }

    /**
     * 获取最近的用户查询记录
     * @param request
     * @return
     */
    @GetMapping("/getSearchUserHistory")
    public List<User> getSearchUserHistory( HttpServletRequest request) {
        String currentUserId = request.getHeader("USER_ID");
        return userService.getSearchUserHistory(currentUserId);
    }

    /**
     * 定时计算:每日的手机销量排行版  list
     * @param request
     * @return
     */
    @GetMapping("/getPhoneSaleRank")
    public List<String> getPhoneSaleRank( HttpServletRequest request) {
        String currentUserId = request.getHeader("USER_ID");
        return null;
    }

    /**
     * 实时计算:每日的手机销量排行版  sorted set
     * @param request
     * @return
     */
    @GetMapping("/getPhoneSaleRank2")
    public List<String> getPhoneSaleRank2( HttpServletRequest request) {
        String currentUserId = request.getHeader("USER_ID");
        return null;
    }

}
